import * as sdk from './fetch';

/**
 *
 * 获取AES key
 *
 */
async function getAesKey(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('getAesKey', {
    ...params,
  });
  return result;
}

/**
 *
 * 查询所有小区
 *
 */
async function findAppCommunity(): Promise<BaseResponseString> {
  let result = await sdk.rzpost('community/findCommunityByCity', {});
  return result;
}

/**
 *
 * 根据经纬度及搜索条件查询社区列表
 *
 */
async function selectDistance(params): Promise<BaseResponseString> {
  let result = await sdk.rzget(
    `community/selectDistance?name=${params.name}&address=${params.address}&longitude=${params.longitude}&latitude=${params.latitude}`,
    {},
  );
  return result;
}

/**
 *
 * 切换房屋
 *
 */
async function updateDefHouse(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('userHouse/updateDefHouse', {
    ...params,
  });
  return result;
}

/**
 *
 * 获取默认小区用户信息
 *
 */
async function getDefHouseInfo(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('house/findDefHouseByUserId', {
    ...params,
  });
  return result;
}

/**
 *
 * 获取首页搜索政务服务
 *
 */
async function getService(params): Promise<BaseResponseString> {
  let result = await sdk.rzget(
    `home/find/service?name=${params.name}&unionId=${params.unionId}&communityId=${params.communityId}`,
    {},
  );
  return result;
}

/**
 *
 * 查询秒杀商品
 *
 */
async function getFlashsaleGoodsList(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`flashsale/xsite/goodsList`, {
    ...params,
  });
  return result;
}

/**
 *
 * 获取首页搜索商城商品(登录)
 *
 */
async function getSearchShopListLogin(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`goods/skus`, {
    ...params,
  });
  return result;
}
/**
 *
 * 获取当前用户信息
 *
 */
async function findDefHouseByUserId(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('house/findDefHouseByUserId', {
    ...params,
  });
  return result;
}
/**
 *
 * 首页公告
 *
 */
async function getIndexNotices(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('notice/findTopN', {
    ...params,
  });
  return result;
}

/**
 *
 * 获取首页搜索商城商品(未登录)
 *
 */
async function getShopListLoginOut(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`goods/skuListFront`, {
    ...params,
  });
  return result;
}
/**
 *
 * 公告列表
 *
 */
async function getNoticeList(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('notice/findPage', {
    ...params,
  });
  return result;
}
/**
 *
 * 获取验证码vCodeType：0：登录，1：暂时未用，2：更换手机号，3：绑定房屋，4：新增车辆，5：修改车辆，6：忘记密码，7：微信登录
 *
 */
async function sendCode(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('sendCode', {
    ...params,
  });
  return result;
}
/**
 *
 * 数字江北大数据中心-获取H5页面接口
 *
 */
async function getMegaDataH5(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('externalPlatform/getMegaDataH5', {
    ...params,
  });
  return result;
}
/**
 *
 * 数字江北大数据中心-获取首页推荐接口
 *
 */
async function getMegaDataExternalUrl(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('externalPlatform/getMegaDataExternalUrl', {
    ...params,
  });
  return result;
}
/**
 *
 * 查询活动列表(首页推荐查询，不分页)
 *
 */
async function getAppFindList(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('activity/appFindList', {
    ...params,
  });
  return result;
}
/**
 *
 * 查询活动列表(分页)
 *
 */
async function getAppFindPageList(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('activity/appFindPageList', {
    ...params,
  });
  return result;
}
/**
 *
 * 查询我的活动
 *
 */
async function findByRegisterBy(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('activity/findByRegisterBy', {
    ...params,
  });
  return result;
}
/**
 *
 * 查询活动类型
 *
 */
async function getActivityType(): Promise<BaseResponseString> {
  let result = await sdk.rzpost('activity/findActivityType', {});
  return result;
}
/**
 *
 * 查询活动详情
 *
 */
async function getActiveDetail(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('activity/findById', {
    ...params,
  });
  return result;
}
/**
 *
 * 活动报名
 *
 */
async function addRegister(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost('activity/addRegister', {
    ...params,
  });
  return result;
}
/**
 *
 * 首页查询热销甄选
 *
 */
async function findShopList(params): Promise<wmBaseResponseString> {
  let result = await sdk.get<wmBaseResponseString>(`magic/d2cStore/000000/weixin/index?storeId=${params.storeId}`, {});
  return result;
}
/**
 *
 * 首页轮播图
 *
 */

async function getAdverImgs(params): Promise<BaseResponseString> {
  let result = await sdk.rzget(
    `advert/findAdvert?type=${params.type}&position=${params.position}&communityId=${params.communityId}`,
    {},
  );
  return result;
}
/**
 *
 * 查询商城基本设置
 *
 */
async function getBaseConfig(): Promise<wmBaseResponseString> {
  let result = await sdk.get<wmBaseResponseString>(`system/baseConfig`, {});
  return result;
}
/**
 *
 * 查询客服
 *
 */
async function getServiceonline(): Promise<BaseResponseString> {
  let result = await sdk.rzget(`jsry/serviceonline/view?serviceOnlineId=1`, {});
  return result;
}

/**
 *
 * 内容营销列表（已登录）
 *
 */
async function findMarketingcontentPage(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`marketingcontent/page`, {
    ...params,
  });
  return result;
}
/**
 *
 * 内容营销列表（未登录）
 *
 */
async function unloginfindMarketingcontentPage(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`marketingcontent/page/unlogin`, {
    ...params,
  });
  return result;
}
/**
 *
 * 内容营销详情
 *
 */
async function getMarketingcontentDetail(params): Promise<wmBaseResponseString> {
  let result = await sdk.get<wmBaseResponseString>(`marketingcontent/${params.id}`, {});
  return result;
}

/**
 *
 * 成长值说明
 *
 */
async function getGrowthSetting(): Promise<wmBaseResponseString> {
  let result = await sdk.get<wmBaseResponseString>(`levelRights/growthSetting`, {});
  return result;
}

export default {
  getAesKey,
  findAppCommunity,
  selectDistance,
  updateDefHouse,
  getDefHouseInfo,
  getService,
  getFlashsaleGoodsList,
  getSearchShopListLogin,
  getShopListLoginOut,
  findDefHouseByUserId,
  getIndexNotices,
  getNoticeList,
  sendCode,
  getMegaDataH5,
  getMegaDataExternalUrl,
  getAppFindList,
  getAppFindPageList,
  findByRegisterBy,
  getActivityType,
  getActiveDetail,
  addRegister,
  findShopList,
  getAdverImgs,
  getBaseConfig,
  getServiceonline,
  findMarketingcontentPage,
  unloginfindMarketingcontentPage,
  getMarketingcontentDetail,
  getGrowthSetting,
};

/**
 * name
 *
 */
export type ISelectDistanceNameReq = string;

/**
 * 正常请求返回
 */
export interface BaseResponseString {
  /**
   * 结果码
   */
  code: string;
  /**
   * 内容
   */
  data?: {
    [k: string]: any;
  };
  /**
   * 错误内容
   */
  errorData?: {
    [k: string]: any;
  };
  /**
   * 状态
   */
  success?: boolean;
  /**
   * 消息内容
   */
  message?: string;
  [k: string]: any;
}
/**
 * 万米请求返回
 */
export interface wmBaseResponseString {
  /**
   * 结果码
   */
  code: string;
  /**
   * 内容
   */
  context?: esGoodsInfoPage;
  /**
   * 错误内容
   */
  errorData?: {
    [k: string]: any;
  };
  /**
   * 状态
   */
  success?: boolean;
  /**
   * 消息内容
   */
  message?: string;
  [k: string]: any;
}
/**
 * 列表数据
 */
export interface esGoodsInfoPage {
  esGoodsInfoPage?: esGoodsInfoPageDetail;
  [k: string]: any;
}
export interface esGoodsInfoPageDetail {
  /**
   * 具体数据内容
   */
  content?: ContentDetailVO[];
  empty?: boolean;
  first?: boolean;
  last?: boolean;
  /**
   * 页码
   */
  number?: number;
  numberOfElements?: number;
  /**
   * 每页条数
   */
  size?: number;
  sort?: null;
  /**
   * 总数据大小
   */
  total?: number;
  totalElements?: number;
  totalPages?: number;
  [k: string]: any;
}

export interface ContentDetailVO {
  goodsInfo?: goodsInfoDetailVO[];
  id?: number;
}
export interface goodsInfoDetailVO {
  goodsInfoImg?: string;
  goodsInfoName?: string;
  marketPrice?: number;
}
export interface AesKeyVO {
  /**
   * key
   */
  key?: string;
  /**
   * need
   */
  need?: string;
  [k: string]: any;
}
//create by moon https://github.com/creasy2010/moon
